<template>
  <div>
    <div class="header flex justify-between align-center px-8">
      <div class="flex align-center">
        <img class="folder-image" src="@/assets/folder.svg" alt="folder" />
        <span class="ml-4">我的文件</span>
      </div>
      <div>
        <a-tooltip>
          <template #title> 新增文件夹 </template>
          <PlusOutlined class="cursor-pointer" @click="addNewFolder" />
        </a-tooltip>
      </div>
    </div>
    <ScrollItem :height="containerHeight" class="contextmenu-active">
      <SubTree :data="data" class="pr-2" v-if="data.length > 0" />
      <div class="flex flex-s h-100 text-999" v-else>选一个模板将会在这生成列表</div>
    </ScrollItem>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import SubTree from "./SubTree.vue";
import { activeItem, getTreeData } from "@/store/utils/project";
import ScrollItem from "../components/ScrollItem.vue";
import { folderConfig } from "@/data/config";
import { PlusOutlined } from "@ant-design/icons-vue";
const data = computed(() => {
  return getTreeData();
});
const containerHeight = ref(0);
onMounted(() => {
  containerHeight.value = window.innerHeight - 106;
});
const addNewFolder = () => {
  let config = folderConfig() as any;
  data.value.unshift(config);
  activeItem(config);
};
</script>

<style lang="scss" scoped>
.header {
  line-height: 48px;
  border-bottom: 1px solid #666;
}

</style>
